package com.yyaccp.appinfo.controller;

import com.yyaccp.appinfo.domain.AppInfo;
import com.yyaccp.appinfo.service.AppCategoryService;
import com.yyaccp.appinfo.service.AppInfoService;
import com.yyaccp.appinfo.service.AppVersionService;
import com.yyaccp.appinfo.util.AjaxResult;
import com.yyaccp.appinfo.util.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/appInfo")
public class AppInfoController {
    @Resource
    private AppInfoService appInfoService;
    @Resource
    private AppCategoryService appCategoryService;
    @Resource
    private AppVersionService appVersionService;
    @GetMapping("/search")
    public AjaxResult search(AppInfo appInfo,
                           @RequestParam(value = "page")  Integer pageindex,
                             @RequestParam(value = "limit")  Integer pageSize){
        Page pageObj = new Page();
        pageObj.setPageindex(pageindex);
        pageObj.setPageSize(pageSize);
        appInfoService.search(appInfo,pageObj);
        List<AppInfo> applist = pageObj.getDatalist();
        for(int i=0;i< applist.size();i++){
            applist.get(i).setCategoryLevel1Name(appCategoryService.getCName(applist.get(i).getCategoryLevel1()));
            applist.get(i).setCategoryLevel2Name(appCategoryService.getCName(applist.get(i).getCategoryLevel2()));
            applist.get(i).setCategoryLevel3Name(appCategoryService.getCName(applist.get(i).getCategoryLevel3()));
        }
       return AjaxResult.success(pageObj);

    }
    @PostMapping("/upappByid")
    public AjaxResult upappByid(AppInfo appInfo){
        int upbyid = appInfoService.upDataByid(appInfo);
        if(upbyid > 0){
            return AjaxResult.success("修改成功success");
        }else{
            return  AjaxResult.error("修改失败error");
        }
    }
}
